package Operation;

import Book.BookList;

import java.util.Scanner;

public class DelOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入图书的名字：");
        String name = input.nextLine();
        int delSize = -1;
        int i = 0;
        for (i = 0; i < bookList.getUsedSize(); i++){
            if (name.equals(bookList.getBook(i).getName())){
                delSize = i;
                break;
            }
        }
        if (i == bookList.getUsedSize()){
            System.out.println("没有找到这本书！");
        }else{
            for (; delSize < bookList.getUsedSize() - 1; delSize++){
                bookList.setBook(delSize,bookList.getBook(delSize + 1));
            }
            bookList.setBook(bookList.getUsedSize() - 1,null);
            bookList.setUsedSize(bookList.getUsedSize() - 1);
            System.out.println("删除完成！");
        }
    }
}
